package com.project.controller;

import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import com.project.domain.entity.BizProjectInSchool;
import com.project.service.IBizProjectInSchoolService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目课题
 */

@Api(tags = "项目课题")
@RestController
@RequestMapping("/pro/inSchool")
public class ProjectInSchoolController extends BaseController {

    @Autowired
    private IBizProjectInSchoolService bizProjectInSchoolService;

    /**
     * 查询校内课题列表
     */
    @PreAuthorize("@ss.hasPermi('system:school:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizProjectInSchool bizProjectInSchool)
    {
        startPage();
        List<BizProjectInSchool> list = bizProjectInSchoolService.selectBizProjectInSchoolList(bizProjectInSchool);
        return getDataTable(list);
    }

    /**
     * 导出校内课题列表
     */
    @PreAuthorize("@ss.hasPermi('system:school:export')")
    @Log(title = "校内课题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizProjectInSchool bizProjectInSchool)
    {
        List<BizProjectInSchool> list = bizProjectInSchoolService.selectBizProjectInSchoolList(bizProjectInSchool);
        ExcelUtil<BizProjectInSchool> util = new ExcelUtil<BizProjectInSchool>(BizProjectInSchool.class);
        util.exportExcel(response, list, "校内课题从数据");
    }

    /**
     * 获取校内课题详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:school:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(bizProjectInSchoolService.selectBizProjectInSchoolByID(ID));
    }

    /**
     * 新增校内课题
     */
    @PreAuthorize("@ss.hasPermi('system:school:add')")
    @Log(title = "校内课题从", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProjectInSchool bizProjectInSchool)
    {
        return toAjax(bizProjectInSchoolService.insertBizProjectInSchool(bizProjectInSchool));
    }

    /**
     * 修改校内课题
     */
    @PreAuthorize("@ss.hasPermi('system:school:edit')")
    @Log(title = "校内课题从", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProjectInSchool bizProjectInSchool)
    {
        return toAjax(bizProjectInSchoolService.updateBizProjectInSchool(bizProjectInSchool));
    }

    /**
     * 删除校内课题
     */
    @PreAuthorize("@ss.hasPermi('system:school:remove')")
    @Log(title = "校内课题从", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(bizProjectInSchoolService.deleteBizProjectInSchoolByIDs(IDs));
    }
}
